import java.time.LocalDateTime;
import java.util.List;
import java.util.UUID;

public class Ticket {
    private String ticketId; // 票号（UUID生成）
    private Show show; // 关联场次
    private List<Seat> seats; // 座位信息
    private double price; // 总价
    private boolean isRefunded; // 是否退票
    private LocalDateTime sellTime; // 售票时间

    public Ticket(Show show, List<Seat> seats, double price) {
        this.ticketId = UUID.randomUUID().toString().substring(0, 8); // 取UUID前8位
        this.show = show;
        this.seats = seats;
        this.price = price;
        this.isRefunded = false;
        this.sellTime = LocalDateTime.now();
    }

    // 检查是否可退票（放映前1小时可退）
    public boolean canRefund() {
        return !isRefunded && LocalDateTime.now().isBefore(show.getTime().minusHours(1));
    }

    // getter和setter
    public String getTicketId() {
        return ticketId;
    }

    public Show getShow() {
        return show;
    }

    public List<Seat> getSeats() {
        return seats;
    }

    public double getPrice() {
        return price;
    }

    public boolean isRefunded() {
        return isRefunded;
    }

    public void setRefunded(boolean refunded) {
        isRefunded = refunded;
    }

    public LocalDateTime getSellTime() {
        return sellTime;
    }
}
    